<template>
  <div id="login">
  <div class="container">
    <div class="header" >
      <img src="../img/left.png" @click="back" >
      <h4>免密登录</h4>
    </div>
    <div class="content">
      <div class="logo">
        <div class="logo-font">logo</div>
        <span>51sendCard</span>
      </div>
    </div>
    <div class="Info">
      <div class="user-Info">
        <input type="text" placeholder="请输入用户名" maxlength="13" id="name" ref="name" />
        <input type="password" placeholder="请输入密码" maxlength="13" id="pwd" ref="pwd"/>
      </div>
    </div>
    <div class="footer">
      <div class="button" @click="login">
        免密登录
      </div>
      <span id="login-tips" :tips="tips">{{tips}}</span>
      <p>点击登录即同意<span>《用户协议》</span>，我们将自动帮助您注册并登陆</p>
      <p style="text-align: right">没有账号？<router-link to="/register"><span>立即注册</span></router-link></p>

    </div>
  </div>
  </div>
</template>
<script>
    export default {
    name:'login',
        data() {
            return {
              tips:"",
            }
        },
        methods: {
        back(){
          this.goback()
        },
        login() {
          var name =this.$refs.name.value;
          var pwd = this.$refs.pwd.value;
          if(name.length == 0){
            this.tips='用户名不能为空';
          }else if(pwd.length == 0){
           this.tips='密码不能为空';
          }else if(pwd.length < 6){
           this.tips='密码长度不能小于6位';
          }else{
            this.tips="";
            var sendJSON={};
            sendJSON.loginName=name;
            sendJSON.loginPwd=pwd;
            this.$http.post(this.urlHost+'user/login.do',JSON.stringify(sendJSON),{
              emulateJSON:true
            }).then(function(res){
             // alert(JSON.stringify(res))
              if(res.body.code!="0000"){
               //alert(res.body.errMsg)
                this.tips=res.body.errMsg;
              }else{
                this.tips="登录成功!";
                setTimeout(() => {
                  this.$router.push({path: 'home'});
                }, 1000);

              }
            },function(res){
              alert(res)
            });
          }
        },
    }}
</script>
<style>
</style>
